package com.fleafinder;

import java.util.List;

import com.fleafinder.entity.Category;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListViewMarketCategoryAdapter extends ArrayAdapter<Category> {
	private final List<Category> list;
	private final Activity context;

	public ListViewMarketCategoryAdapter(Activity context, List<Category> list) {
		super(context, R.layout.listview_market_category_layout, list);
		this.context = context;
		this.list = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.listview_market_category_layout,
					null);
		} else {
			view = convertView;
		}
		
		TextView text = (TextView) view
				.findViewById(R.id.textView_category);
		text.setText(list.get(position).getName());
		text.setTag(list.get(position).getId());

		return view;
	}
}
